import requests

from common.get_header import get_token

i = get_token()
# 封装  类  -  接口对象层
class EmpManageApi(object):
    # 添加员工
    def add_emp(self,req_head,req_data):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head,
                             json=req_data)
        return resp
    # 查询员工
    def query_emp(self,req_id,req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/"+req_id,
                            headers=req_head)
        return resp
    # 修改员工
    def modify_emp(self,req_id,req_head,req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/"+req_id,
                            headers=req_head,
                            json=req_body)
        return resp
    # 删除员工
    def del_emp(self,req_id,req_head):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/"+req_id,
                               headers=req_head)
        return resp


    # ihrm 登录
    def login_ihrm(self,req_body):
        # 发送 post 请求
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                             json=req_body)
        return resp





if __name__ == '__main__':
    req = EmpManageApi()
    # 准备请求头
    req_head = {"Authorization":"e1438c1c-58e0-4efa-adb4-2db920768e43"}
    # 准备 请求体
    req_body = {
        "username": "jack123",
        "mobile": "13858030416",
        "workNumber": "666"
    }
    resp = req.add_emp(req_head,req_body)
    print(resp.json())

    # # 准备 员工id
    # req_id = "1568923953378897920"
    # # 准备 请求头
    # req_head = {"Authorization": "e1438c1c-58e0-4efa-adb4-2db920768e43"}
    # resp = req.query_emp(req_id,req_head)
    # print(resp.json())
    #
    #
    # # 准备 员工id
    # req_id = "1568923953378897920"
    #
    # # 准备 请求头
    # req_head = {"Authorization": "e1438c1c-58e0-4efa-adb4-2db920768e43"}
    # # 准备 请求体
    # req_body = {"username": "小猪噜噜"}
    #
    # resp = req.modify_emp(req_id,req_head,req_body)
    # print(resp.json())
    #
    #
    #
    # # 准备 员工id
    # req_id = "1568923953378897920"
    #
    # # 准备 请求头
    # req_head = {"Authorization": "e1438c1c-58e0-4efa-adb4-2db920768e43"}
    #
    # resp = req.del_emp(req_id,req_head)
    # print(resp.json())

    # 准备 请求头
    # resp = {"mobile": "13800000002", "password": "123456"}
    # i = req.login_ihrm(resp)
    # print(i.json())
